<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link type="text/css" rel="stylesheet" href="/Store/Public/Admin/css/H-ui.css"/>
<link rel="stylesheet" type="text/css" href="/Store/Public/layui/css/layui.css"></link>
<script type="text/javascript" src="/Store/Public/Admin/js1/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="/Store/Public/layer/layer.js"></script>
<script>
/*
*live--当点击按钮时，隐藏或显示
*children(i)--遍历对象的i表单
*removeClass()删除指定元素的类
*addClass()添加指定的元素的类
*html()设置被选元素的内容
*
*/
$(function(){
	  $('.enable').live('click',function(){
		  var $linkObj=$(this);
		  var $imgObj=$(this).children('i');
		  $.post('/Store/index.php/Admin/Role/disable','id='+$(this).attr('data-id'),function(){
			  $linkObj.removeClass('enable').addClass('disable');
			  $imgObj.html('<i class="layui-icon" >&#xe616;</i>');
		  });
	  })
	  $('.disable').live('click',function(){
		  var linkObj=$(this);
		  var imgObj=$(this).children('i');
		  var id=$(this).attr('data-id');
		  var status=$(this).attr('data-status');
		  
		   $.post('/Store/index.php/Admin/Role/enable',{id:id,status:status},function(){
			  linkObj.removeClass('disable').addClass('enable');
			  imgObj.html('<i class="layui-icon">&#x1007;</i>');
			
		  });
	  }) 
})

</script>
</head>
<body>
 <div class="cl pd-5 bg-1 bk-gray mt-20">
    <span class="l"><a href="javascript:;" onClick="datadel()" class="btn btn-danger radius"><i class="icon-trash"></i> 批量删除</a>
    <a href="javascript:void(0);"class="btn btn-primary radius" id="save1"><i class="icon-plus"></i> 添加用户</a></span>
    <span class="r">共有数据：<strong><?php echo ($num); ?></strong> 条</span>
  </div>

<table class="layui-table" >
  <colgroup>
    <col width="150">
    <col width="200">
    <col>
  </colgroup>
  <thead>
    <tr>
      <th>id</th>
      <th>用户名称</th>
      <th>加入时间</th>
      <th>邮箱</th>
      <th>状态</th>
      <th>操作</th>
    </tr> 
  </thead>
  <tbody>
   <?php if(is_array($arr)): foreach($arr as $key=>$v): ?><tr class="a<?php echo ($v["id"]); ?>">
      <td><?php echo ($v["id"]); ?></td>
      <td><?php echo ($v["name"]); ?></td>
      <td><?php echo ($v["updated_time"]); ?></td>
      <td><?php echo ($v["email"]); ?></td>
      <?php if($v["status"] == 1): ?><td><a href="javascript:void(0)" class="enable" data-id="<?php echo ($v["id"]); ?>" data-status="<?php echo ($v["status"]); ?>"><i class="layui-icon" >&#xe616;</i></a></td>
      <?php else: ?>
      <td><a href="javascript:void(0)" class="disable" data-id="<?php echo ($v["id"]); ?>"><i class="layui-icon">&#x1007;</i></a></td><?php endif; ?>
      <td><a href="javascript:void(0)" class="edit" data-email="<?php echo ($v["email"]); ?>" data-name="<?php echo ($v["name"]); ?>" data-id="<?php echo ($v["id"]); ?>" title="编辑"><i class="layui-icon" style="background:#e2e2e2">&#xe642;</i></a>
      &nbsp;&nbsp;
      <a href="javascript:void(0)" class="shanchu" title="删除" data-id="<?php echo ($v["id"]); ?>"><i class="layui-icon" style="background:#e2e2e2">&#xe640;</i></a>
        &nbsp;
      <a href="javascript:void(0)" class="add" data-id="<?php echo ($v["id"]); ?>" title="添加"><i class="layui-icon" style="background:#e2e2e2">&#xe654;</i></a></td>
    </tr><?php endforeach; endif; ?>
  </tbody>
</table>

<div><?php echo ($pageStr); ?></div>
<script>
/*  
 * 添加
 */
$('.add').click(function(){
	layer.open({
		type:2,
		content:"/Store/index.php/Admin/User/user_add",
		area:['800px','400px'],
		title:['添加角色','background:#e2e2e2;align:center'],
		shift:3,
	})
	
}) 
/* 
 * 添加
 */
$('#save1').click(function(){
	layer.open({
		type:2,
		content:"/Store/index.php/Admin/User/user_add",
		area:['800px','400px'],
		title:['添加角色','background:#e2e2e2;align:center'],
		shift:3,
	})
}) 
/* 
*删除
*/
$('.shanchu').click(function(){
	var id=$(this).attr('data-id');
	layer.confirm('确认要删除吗！',function(){
		$.post("/Store/index.php/Admin/User/delete",{id:id},
		     function(data){
			$('.a'+id).remove();
			   if(data.a=="pass"){
				   layer.msg('已删除',{icon:1,time:1000});
				  
			   } 
		})
	})
})
/* 
 * 编辑
 */
 $('.edit').click(function(){
	 var id=$(this).attr('data-id');
	 var name=$(this).attr('data-name');
	     if(name.length<1){
	    	 layer.msg('用户不能为空！');
	     }
	 var email=$(this).attr('data-email');
		 layer.open({
		 type:2,
		 content:"/Store/index.php/Admin/User/alter?name="+name+"&email="+email+"&id="+id,
		 area:['800px','400px'],
		 title:['编辑用户','background:#e2e2e2;align:center'],
		 shift:3,
	 }) 
   
 })
</script>
</body>
</html>